//fetch请求
let ServerAgent = {
    invoke: async (api, data) => {
        let res = await fetch(`http://localhost:3000/${api}`, {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'text/plain',
                'Accept-Charset': 'UTF-8'
            },
            body: JSON.stringify(data || {}),
        });
        let pck = await res.json();
        if(pck.error){
            alert(pck.error);
            throw "";
        }
        return pck;
    }
};
let getAgent = function (naive) {
    return {
        invoke: async (api, data) => {
            let res = await fetch(`http://api.zankong.com.cn:1259/naive/${naive}/invoke/${api}`, {
                method: 'POST',
                headers: {
                    'Accept': 'application/json',
                    'Content-Type': 'text/plain',
                    'Accept-Charset': 'UTF-8'
                },
                body: JSON.stringify(data || {}),
            });
            let pck = await res.json();
            if(pck.error){
                alert(pck.error);
                throw "";
            }
            return pck;
        }
    }
};

let getParams = ()=>{
    let strHref = location.href;
    let intPos = strHref.indexOf("?");
    let strRight = strHref.substr(intPos + 1);
    let arrTmp = strRight.split("&");
    let data = {};
    for(let i = 0; i < arrTmp.length; i++) {
        let arrTemp = arrTmp[i].split("=");
        try{
            data[arrTemp[0]] = arrTemp[1];
        }catch(e) {
        }
    }
    return data;
};